package bilibili;

import java.util.Scanner;

/**
 * @author Hang
 * @date 2022/9/1
 * @project AutumnOffer
 * @description
 **/
public class Solution1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1;i<=n;i++){
            dp[i] = i+1;
            for(int j=2;j<=i/2;j++){
                if(i%j==0){
                    dp[i] = Math.min(Math.min(i/j+j,dp[i]),dp[i/j]+j);
                }
            }
        }
        System.out.println(dp[n]);
    }
}
